<?php
class Files_model extends CI_Model{

	function insert_db($info){

		$this->db->insert('files',$info);

		}

	function get_last_10(){
		$query = $this->db->get('files',10);
		return $query->result();
	}	

	function get_files($doc_type,$partner,$order,$created_from,$created_to){
		$this->db->select('*');

		if($doc_type!='sve'){
			$this->db->where('doc_type',$doc_type);
		}

		if($partner!='sve'){
			$this->db->where('partner',$partner);
		}
		
		if (($created_from!='')&($created_to!='')){
			$this->db->where('created_on >=',$created_from);
			$this->db->where('created_on <=',$created_to);
		}

		$this->db->from('files');
		$this->db->order_by('created_on',$order);

	
		$query = $this->db->get();
		return $query->result();
	}



	function get_files_query($doc_type,$order,$created_from,$created_to){

		
		
		if($doc_type!='sve'){
		$sql = "SELECT * FROM files
				WHERE doc_type = ? 


		";
		
		$query = $this->db->query($sql,array($doc_type));
		
		}
		else{
		$sql = "SELECT * FROM files 

		";

		$query = $this->db->query($sql);
		
		}


		return $query->result(); 
	}



	function get_pag_files($per_page,$doc_type,$order){


		if($doc_type!='sve'){
			//$query = $this->db->select('path, doc_type')->where('doc_type',$doc_type)->order_by('created_on',$order)->get('files',$per_page,$this->uri->segment(3));
			//$per_page = $this->db->get_where('files',array('doc_type' => $doc_type ))->num_rows();
			//$query = $this->db->select('path, doc_type')->get_where('files',array('doc_type' => $doc_type ),$per_page,$this->uri->segment(3));

			$query = $this->db->order_by('created_on',$order)->get('files',$per_page,$this->uri->segment(3));

			//$this->db->where('doc_type',$doc_type);
			//$this->db->order_by('created_on',$order);
			//$query = $this->db->get('files',$per_page,$this->uri->segment(3));

		}
		else
		{
			//$query = $this->db->select('path, doc_type')->order_by('created_on',$order)->get('files',$per_page,$this->uri->segment(3));

			$query = $this->db->order_by('created_on',$order)->get('files',$per_page,$this->uri->segment(3));
		}

		return $query;
		
	}

	//$data['records'] = $this->db->select('path, doc_type')->get('files',$data['per_page'],$this->uri->segment(3));

	function update($id,$info){

		$this->db->where('id',$id);
		$this->db->update('files',$info);

	}
}

?>